package sharping.appilog.Adapter;

import java.util.ArrayList;

import sharping.appilog.R;
import sharping.appilog.app;
import sharping.appilog.DataTree.BizInfo.Review;
import sharping.appilog.Logic.Check_Value;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.android.volley.toolbox.NetworkImageView;

public class BizInfoListAdapter extends BaseAdapter {

	private ArrayList<Review> items;
	private int count;
	
	private Context context;
	
	public BizInfoListAdapter(Context context, ArrayList<Review> reviews, int headerCount) {
		this.context = context;
		this.items = reviews;
		
		if (reviews == null) {
			this.count = 0;
		} else {
			this.count = reviews.size();
		}
	}

	@Override
	public int getCount() {
		return count;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		final int real_position = position;
		
		holder v;
		
		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(R.layout.list_comment, null);
			
			v = new holder();
			
			v.userimg = (NetworkImageView) convertView
					.findViewById(R.id.details_timeline_comment_img);
			v.name = (TextView) convertView
					.findViewById(R.id.details_timeline_comment_name);
			v.message = (TextView) convertView
					.findViewById(R.id.details_timeline_comment_message);
			v.writetime = (TextView) convertView
					.findViewById(R.id.timeline_write_time);
			
			convertView.setTag(v);
		} else {
			v = (holder) convertView.getTag();
		}
		
		v.userimg.setImageUrl(app.HOST_URL + "rmobile/" + items.get(real_position).getCUserImgURL(), app.mImageLoader);
		v.name.setText(items.get(real_position).getCUserName());
		v.message.setText(items.get(real_position).getCReplyMessage());
		v.writetime.setText(Check_Value.setDateTimeMessage(items.get(real_position).getCReplyDate()));
		
		return convertView;
	}
	
	private class holder {
		NetworkImageView userimg;
		TextView name, message, writetime;
	}

	@Override
	public Object getItem(int position) {
		return items.get(position);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

}
